package com.agriculture.data_demo.repository;

import com.agriculture.data_demo.entity.sys.HogDailyEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @author morningbear
 * @date 20.10.7
 * @update 20.10.19
 */
@Repository
public interface HogDailyRepository extends JpaRepository<HogDailyEntity, Integer> {

    @Query(value = "select * from hog_daily", nativeQuery = true)
    Page<HogDailyEntity> findAll(PageRequest of);

    /**
     *
     * @param fence 猪舍类型
     * @return 根据猪舍类型寻找
     */
    @Query(value = "select * from hog_daily where fence = ?1", nativeQuery = true)
    Page<HogDailyEntity> findByFence(String fence, Pageable pageable);

    /**
     *
     * @param startDate 起始日期
     * @param endDate 截至日期
     * @return 一段时间内的肉猪生产周期数据
     */
    @Query(value = "select * from hog_daily where hog_daily.create_at between ?1 and ?2", nativeQuery = true)
    Page<HogDailyEntity> findHogDailyEntitiesByDate(Date startDate, Date endDate, Pageable pageable);
}
